/**
 * Copyright (c) Jan 14, 2013 11:33:57 AM WKM and/or its affiliates. 
 * Use is subject to license terms.
 * All rights reserved.
 */
package org.extblog.wkm.web.action.test;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.junit.Before;
import org.springframework.web.servlet.HandlerAdapter;
import org.springframework.web.servlet.HandlerExecutionChain;
import org.springframework.web.servlet.HandlerMapping;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;



/**
 * @author WKM
 * JUnitActionBase.java history
 * 1.WKM - Jan 14, 2013 - Create File
 */
public abstract class JUnitActionBase {
	//测试用例
	public String localName = "wkm.cn";
	
	private HandlerMapping handlerMapping = null;
	
	private HandlerAdapter handlerAdapter = null;
	
	@Before
	public void init(){
		handlerMapping = new RequestMappingHandlerMapping();
		handlerAdapter = new RequestMappingHandlerAdapter();
	}
	
	public ModelAndView excuteAction(HttpServletRequest request, HttpServletResponse response){
		try{
			HandlerExecutionChain chain = handlerMapping.getHandler(request);  
	        final ModelAndView model = handlerAdapter.handle(request, response,  
	                chain.getHandler());  
	        return model;
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			System.out.println("----" + e.getMessage());
		}
		return null;
	}
}
